<template>
	<view>
		<camera frame-size='large'></camera>
		<button class='record' @click="uploadPhoto">拍照</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			};
		},
		methods: {
			uploadPhoto(e) {
				let that = this;
				wx.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album', 'camera'],
					success(res) {
						let tempFilePaths = res.tempFilePaths;
						that.upload(tempFilePaths);
					}
				})
			},
			upload(path) {
				wx.showToast({
					icon: "loading",
					title: "正在上传……"
				});
				wx.uploadFile({
					url: '上传图片接口url',
					filePath: path[0],
					name: 'file',
					header: {
						"Content-Type": "multipart/form-data"
					},
					success(res) {
			  	if (res.statusCode != 200) {
							wx.showModal({
								title: '提示',
								content: '上传失败',
								showCancel: false
							});
							return;
						} else {
							console.log("上传成功！ 可对返回的值进行操作，比如：存入imgData；");
						}
					},
					fail(e) {
						wx.showModal({
							title: '提示',
							content: '上传失败',
							showCancel: false
						});
					},
					complete() {
						wx.hideToast();
					}
				})
			}
		}
	}
</script>

<style>

</style>
